﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using app.Models;
using AmuTools;

namespace app.Api
{
    /*
        数据库的初始化，备份等操作

        初始化的目的是保证一些必要的数据添加到数据库中，甚至可以自动建立表（通过执行sql文件代码）等
    */
    public class ApiCheck : ApiBase
    {
        public ApiCheck(Controller ctx) : base(ctx) { }

        #region 自定义请求参数
        // 作者
        string req_author { get { return GetStringParam(new ReqStringParamOption { Name = "author", Level = REQPARAMLEVEL.FREE }); } }

        #endregion

        public void Do(string action)
        {
            switch (action)
            {
                case "investment_pass":
                    {
                        Investment investment = G.DB.GetById<Investment>(req_id);
                        investment.status = (int)INVESTMENT_STATUS.POSTED;
                        G.DB.Update<Investment>(investment);
                        ResponseJson(new Result());
                        break;
                    }
                case "investment_failed":
                    {
                        Investment investment = G.DB.GetById<Investment>(req_id);
                        investment.status = (int)INVESTMENT_STATUS.FAILED_EXAMINE;
                        G.DB.Update<Investment>(investment);
                        ResponseJson(new Result());
                        break;
                    }
                case "investment_list":
                    {
                        ResponseJson(GetPageResult<Investment>(string.Format("status ={0}",(int)INVESTMENT_STATUS.EXAMINING), G.DB.GetPrimaryKey<Investment>()));
                        break;
                    }
                default: break;
            }
        }
    }


}